package appserver.avro;

import java.net.InetSocketAddress;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

import org.apache.avro.AvroRemoteException;
import org.apache.avro.ipc.NettyTransceiver;
import org.apache.avro.ipc.specific.SpecificRequestor;

import com.alibaba.fastjson.JSON;

import tt.dz.appserver.service.avro.client.main.MSRPCService;
import tt.dz.appserver.service.avro.client.oms.dzttOmsServiceProtocol;
import tt.dz.appserver.service.avro.client.order.dzttOrderServiceProtocol;
import tt.dz.appserver.service.avro.server.RpcAppService;
import tt.dz.appserver.util.http.HttpUtils;

public class OmsClient {

	public class Oms{
	}
	private static String host = "139.224.33.36";
	private static int port = 7002;
	private static String orderhost = "139.224.33.114";
	private static int orderport = 65222;
	private static String mshost = "192.168.5.202";
	private static int msport = 65111;
	

	private static String apphost = "127.0.0.1";
	private static int appport = 8080;
	
	private static dzttOmsServiceProtocol proxy;
	private static dzttOrderServiceProtocol orderProxy;
	private static MSRPCService msrpcService;
	private static RpcAppService appService;

	public void start() throws Exception {
		
		NettyTransceiver client = new NettyTransceiver(new InetSocketAddress(host, port));
		proxy = SpecificRequestor.getClient(dzttOmsServiceProtocol.class, client);
		
		NettyTransceiver avroClient = new NettyTransceiver(new InetSocketAddress(orderhost, orderport));
		orderProxy = SpecificRequestor.getClient(dzttOrderServiceProtocol.class, avroClient);

		//NettyTransceiver msClient = new NettyTransceiver(new InetSocketAddress(mshost, msport));
		//msrpcService = SpecificRequestor.getClient(MSRPCService.class, msClient);
		
		//NettyTransceiver appClient = new NettyTransceiver(new InetSocketAddress(apphost, appport));
		//appService = SpecificRequestor.getClient(RpcAppService.class, appClient);
	}


	public static void main(String[] args){
		try {
			new OmsClient().start();
			String resultJsonString="";
			// resultJsonString=proxy.getMapDataPackage(null).toString();
			//System.out.println(resultJsonString);
			
			//System.out.println(getStationByCoordinate());
			
			
			//app --
			Map<String,String> paramMap = new HashMap<String,String>();
			paramMap.put("userId", "userId");
			paramMap.put("stationId", "1234");
			paramMap.put("grade", "0");
			paramMap.put("address", "address");
			paramMap.put("content", "content");
			//String a=HttpUtils.postRequest("127.0.0.1:8080/station/stationComment", paramMap, true);
			//System.out.println(a);
			Map<String,String> m = new HashMap<String,String>();
			m.put("provinceId", "01000001");
			//appService.stationUpdateNotify(JSON.toJSONString(m));
			
			//System.out.println(msrpcService.getCheckCode(JSON.toJSONString(m)));
//			System.out.println(proxy.getChargerPortStatus("0028300000000047","1"));

			//Map<String,String> m = new HashMap<String,String>();
			paramMap = new HashMap<String,String>();
			paramMap.put("provinceId", "01000001");
//			System.out.println(appService.stationUpdateNotify(JSON.toJSONStringparamMapm)));
			
//			System.out.println(proxy.getChargerPortsByChargerId("0010300000000101"));
//			System.out.println(proxy.chargeReservation("18808002810000002580", "0028300000000011", "0"));
//			System.out.println(proxy.getQiniuyunUpToken(null));
//			System.out.println(proxy.getReservationDiscount("18808002810000002580", "0", "0028300000000011", "1200", DateUtil.getDateTime()));
			//System.out.println(proxy.startCharge("000000000001", "18808002810000002580", "1"));
			String userCard="18808000010000000138";
			
			resultJsonString=proxy.getChargerDetailByChargerId("0000300000000011").toString();
			System.out.println(resultJsonString);
			/*System.out.println(proxy.getChargeInfoAndBespeakInfoByUserPayCard("18808002810000002580"));
			Scanner scan = new Scanner(System.in);
			  String read = scan.nextLine();
			System.out.println(proxy.closeCharge(read));
			String sss="";*/
			//  0104300000000253554321  0104400000000987718765 0104400000000258028765
			System.out.println(proxy.getBespeakDetailInfoByOrderNo("0104300000000253544321"));
			System.out.println(proxy.getChargeDetailInfoByOrderNo("0104300000000253544321"));
			System.out.println(orderProxy.findOrderItemsByOrderNo("0104300000000253544321"));
//			System.out.println(proxy.getChargerListByStationId("51011600010000000001"));
//			System.out.println(proxy.startCharge("18805002810000001661", "0028300000000184", "1"));
//			System.out.println(proxy.getChargerPortStatus("0028300000000001", "1"));
//			System.out.println(proxy.getChargerRate("0010300000000101"));
			System.out.println(proxy.getMapDataPackage(null));
			System.out.println(proxy.cooperationType(null));
//			System.out.println(proxy.applyCooperation("123", "123"));
//			System.out.println(proxy.getErrorCode(null));
//			System.out.println(proxy.stationErrorInfo("123", "1"));
//			System.out.println(proxy.getChargerRate("0028300000000285"));
//			System.out.println(proxy.getExternalStation(""));
			//System.out.println(proxy.getChargerPortStatus("0028300000000013", "1"));
//			System.out.println(proxy.getChargerDetailByQrCode("000000000022"));
//			System.out.println(proxy.getChargerListByStationId("51011600011160910001"));
//			System.out.println(proxy.getChargerPortStatus("0851300000000011", "1"));
//			System.out.println(proxy.getFreeChargerByStationId("51011600010000000001"));
//			System.out.println(proxy.getStationDetailByStationId("51011600010000000001"));
//			System.out.println("ol..");
			//String order=proxy.getChargeDetailInfoByOrderNo("3000201610101514101376").toString();
			///System.out.println(order);
			String resultJsonString2 = proxy.getChargerRate("0000300000000023").toString();
			System.out.println("费率="+resultJsonString2);
			Map<String,String> params = new HashMap<String,String>();
			params.put("condition", "2");
			params.put("userId", "01112016032900000289");
			params.put("pageNo", "1");
			params.put("pageSize", "20");
			
			//main  
			Map<String,String> isExist = new HashMap<String,String>();
			isExist.put("mobileNo", "15334561234");
			isExist.put("merchantCode","1201601001");
			isExist.put("sysCode", "124");//渠道号
			System.out.println(msrpcService.userIsExists(JSON.toJSONString(isExist)));
			
			Map<String,String> productMap = new HashMap<String,String>();
			productMap.put("mobileNo", "15334561234");
			productMap.put("merchantCode","1201601001");
			productMap.put("sysCode", "124");//渠道号
			System.out.println(msrpcService.userIsExists(JSON.toJSONString(isExist)));
			
			 params = new HashMap<String,String>();
			params.put("mobileNo", "15334561234");
			params.put("merchantCode", "1201601001");
			//发送验证码
			//String resultJsonString ="";
			// resultJsonString = msrpcService.getCheckCode(JSON.toJSONString(params)).toString();
			// 返回的验证码
			 // 974215
			 params = new HashMap<String,String>();
				params.put("mobileNo", "15334561234");
				params.put("checkCode", "974215");
			//	resultJsonString= msrpcService.verifyCheckCode(JSON.toJSONString(params)).toString();
			 System.out.println(resultJsonString);
			 
			 
			//注册
			 params = new HashMap<String,String>();
				params.put("mobileNo", "15334561234");
				params.put("channel", "124");
				params.put("merchantCode", "1201601001");
				//resultJsonString= msrpcService.regist(JSON.toJSONString(params)).toString();
				// System.out.println("regist="+resultJsonString);
				//绑定
				 params = new HashMap<String,String>();
					params.put("tokenKey", "15334561234");
					params.put("bindType", "1");
					params.put("thirdUuuid", "15334561234");
					params.put("merchantCode", "1201601001");
					params.put("sysCode", "124");
					//resultJsonString= msrpcService.bindThirdAccount(JSON.toJSONString(params)).toString();
				 System.out.println("bindThirdAccount="+resultJsonString);
				
			 //自动登录
			 params = new HashMap<String,String>();
				params.put("loginKeyToken", "12345612");
				params.put("loginType", "3");
				params.put("merchantCode", "0201610047");
				params.put("sysCode", "124");
				resultJsonString= msrpcService.login(JSON.toJSONString(params)).toString();
				 System.out.println("login="+resultJsonString);
			 
			 
//			System.out.println(orderProxy.orderHistoryQuery(JSON.toJSONString(params)));
			Runtime.getRuntime().exit(1);
		} catch (Exception e1) {
			e1.printStackTrace();
		}
	}
	/**
	 * 按坐标获取站点
	 * @return
	 * @throws AvroRemoteException
	 */
	public static String  getStationByCoordinate() throws AvroRemoteException{
		Map<String, String> params = new HashMap<String, String>();
		params.put("x", "1");
		params.put("y", "2");
		params.put("number",20+"");

		String resultJsonString = proxy.getStationByLocation("104.062918","30.546308","20").toString();
		System.out.println(resultJsonString);
		//String resultJsonString2=proxy.getStationByName("成都","510100").toString();
		String resultJsonString3=proxy.getStationByName("成都","").toString();
		//System.out.println(resultJsonString2);
		System.out.println(resultJsonString3);
		return "";
	}
	
}
